import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login'
import Home from '@/views/Home'
import Register from '@/views/Register'
import UserInfo from '@/views/UserInfo'
import Setting from '@/views/Setting'

Vue.use(VueRouter)

//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
    return originalReplace.call(this, location).catch(err => err)
}


const routes = [
	{
		path: '/',
		name: 'Login',
		component: Login,
		hidden: true
	},
	{
		path: '/home',
		name: '',
		component: Home,
		children: [
			{
				path: '/userInfo',
				name: '个人信息',
				component: UserInfo,
				hidden: true
			},
			{
				path: '/setting',
				name: '设置',
				component: Setting,
				hidden:true
			}
		]
	},
	{
		path: '/register',
		name: 'Register',
		component: Register,
		hidden: true
	},
]

const router = new VueRouter({
	mode: 'hash',
	routes
})

export default router
